<?php
!defined('IN_ROOT') && exit( 'Access Denied' );
class AreaController extends AdminModuleController 
{
	public function actionAdmin() {
		$page = intval(getgpc('page'));
		if (!$page) $page = 1;
		
		$fid = getgpc(2);
		if(!$fid) {
			$sqladd = "fId=1 ";
		} else {
			$sqladd = "fId='$fid' ";
		}
		$this->view->assign('fid', $fid);
		$areaList = $this->AreaModel->findAll($sqladd, $page, GODHOUSE_PPP3, 'id ASC');
		
		$fid = getgpc($fId);
		if(!$fid) {
			$sqladds = "fId=1 ";
		}
		$areaTop = $this->AreaModel->findAll($sqladds, $page, GODHOUSE_PPP3, 'id ASC');
		
		$num = $this->AreaModel->count($sqladd);
		$this->view->assign('areaList', $areaList);
		$this->view->assign('areaTop', $areaTop);
		$this->display('area_admin');
	}
	
	public function actionCreate(){
		
		$areaList = $this->AreaModel->findAll("fId='1' ", 0, 0, 'id ASC');
		if (isset($_POST['area'])) {
			$area = $_POST['area'];
			$this->AreaModel->insert($area);
			$this->message('添加成功。', GODHOUSE_DOMAIN_WWW."admin/area-create.htm");
		}
		
		$this->view->assign('areaList', $areaList);
		$this->display('area_create');
	}
	public function actionUpdate(){
			$id = getgpc(2);
		$areaList = $this->AreaModel->find("id='$id' ", 0, 0, 'id ASC');
			$name = $areaList['name'];
		if (isset($_POST['area'])) {
			$area = $_POST['area'];
			$this->AreaModel->updateByPk($id, $area);
			$this->message('修改成功。', GODHOUSE_DOMAIN_WWW."admin/area-update-$id.htm");
		}
		$this->view->assign('name', $name);
		$this->view->assign('areaList', $areaList);
		$this->display('area_update');
	}
	public function actionDelete(){
		$id = getgpc(2);
		$fId = getgpc(3);
		$this->areaModel->deleteByPk($id);
		$this->areaModel->delete("fid='$id'");
		$this->message('删除成功。', GODHOUSE_DOMAIN_WWW."admin/area-admin-$fId.htm");
		
	}
}
?>